package SoftwareEngineering01.WordFrequence.Step1;

import SoftwareEngineering01.WordFrequence.Step0.Counting;
import SoftwareEngineering01.WordFrequence.readFile.CompareWith;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class Counting_01L {
    public static void counting_01L(String string,int n){
        Map<String,Integer> map = Counting_01.getWordMap(string);
        List<Map.Entry<String,Integer>> list = new ArrayList<>();
        list.addAll(map.entrySet());
        CompareWith compareWith = new CompareWith();
        Collections.sort(list,compareWith);
        int k = n;
        for(Map.Entry<String,Integer> item:list){
            System.out.println(item.getKey()+"出现的次数共有:"+item.getValue());
            k++;
            if(k >= n)
                break;
        }
    }
}
